/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "TransactionViewDialog.h"

#include <QtCore/QTime>
#include <QtGui/QEvent.h>
#include <QtGui/QMessageBox>

#include <QtGui/QGridLayout>
#include <QtGui/QPushButton>

#include <QtGui/QHBoxLayout>
#include <QtGui/QTextBlock>
#include <QtGui/QLabel>

namespace QSThink
{

	TransactionViewDialog::TransactionViewDialog(QWidget *parent,Qt::WindowFlags flag)
		:QDialog(parent,flag),_ui(new Ui::TransactionViewUI)
	{
		_ui->setupUi(this);
	}

	TransactionViewDialog::~TransactionViewDialog()
	{

	}

	void TransactionViewDialog::load( Transaction1Day* trans )
	{
		this->setWindowTitle(Utilities::getDateStr(trans->date()));

		_ui->tableWidget->clearContents();
		_ui->tableWidget->setRowCount(0);//first load zero

		if(trans->loadData()){
			int cnt=trans->getTransCount();
			_ui->tableWidget->setRowCount(cnt);
			for(int i=0;i<cnt;++i){

				TransactionSingle* t=trans->getTransaction(i);

				QString timeStr=Utilities::getTimeStr(t->time);
				float price=(float)t->price/100;
				QString type=Utilities::getTransTypeStr(t->flag);
				QTableWidgetItem *timeItem = new QTableWidgetItem(timeStr);
				QTableWidgetItem *priceItem = new QTableWidgetItem(QString::number(price));
				QTableWidgetItem *volumeItem = new QTableWidgetItem(QString::number(t->volume));
				QTableWidgetItem *amountItem = new QTableWidgetItem(QString::number(t->amount));
				QTableWidgetItem *typeItem = new QTableWidgetItem(type);


				_ui->tableWidget->setItem(i,0, timeItem);
				_ui->tableWidget->setItem(i,1, priceItem);
				_ui->tableWidget->setItem(i,2, volumeItem);
				_ui->tableWidget->setItem(i,3, amountItem);
				_ui->tableWidget->setItem(i,4, typeItem);



			}


		}


	}


	
}
